home *** CD-ROM | disk | FTP | other *** search
- #
- # tarcomp: Determines whether the system 'tar' is capable of decompressing.
- # files automatically. The command tar is used unless another is
- # specified in the variable TARPROG.
- # Returns 'true' (0) if the tar program can decompress, 'fail' if it cannot.
- #
- tarcomp() {
-
- # Set TARPROG to default of tar if not set.
- : ${TARPROG:=tar}
- tctmp=/tmp/tc$$ # Name for tmp files.
-
- # Eminently compressible data to go into file. (60 'a's)
- _ptrn="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-
- echo ${_ptrn} | compress -F > $tctmp.A # Compress data.
-
- # Tar to an archive file, with headers set to indicate compression.
- ${TARPROG} Cf $tctmp.T $tctmp.A 2>/dev/null || {
- rm -rf $tctmp.*
- return 1
- }
-
- # Now restore original file from archive - it should automagically
- # be decompressed.
- rm -f $tctmp.A
- ${TARPROG} xf $tctmp.T 2>/dev/null || {
- rm -rf $tctmp.*
- return 1
- }
-
- # Compare it to the original data.
- echo ${_ptrn} | cmp -s - $tctmp.A 2>/dev/null || {
- rm -rf $tctmp.*
- return 1
- }
-
- # If we got here, the two compared equal, which
- # implies that the compress/decompress cycle worked.
- rm -rf $tctmp.*
- return 0
- }
-